/*     */ package com.feeyin.radar.sys.service.impl;
/*     */ 
/*     */ import com.feeyin.radar.commons.DateUtils;
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.sys.dao.BusinessTargetDAO;
/*     */ import com.feeyin.radar.sys.dao.DepartmentDAO;
/*     */ import com.feeyin.radar.sys.dao.ManageSetDAO;
/*     */ import com.feeyin.radar.sys.dao.UserDAO;
/*     */ import com.feeyin.radar.sys.form.BusinessTargetForm;
/*     */ import com.feeyin.radar.sys.form.MonthTargetForm;
/*     */ import com.feeyin.radar.sys.model.BusinessTarget;
/*     */ import com.feeyin.radar.sys.model.Department;
/*     */ import com.feeyin.radar.sys.model.ManageSet;
/*     */ import com.feeyin.radar.sys.model.ManageSetObject;
/*     */ import com.feeyin.radar.sys.model.Users;
/*     */ import com.feeyin.radar.sys.service.BusinessTargetService;
/*     */ import java.io.PrintStream;
/*     */ import java.math.BigDecimal;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ 
/*     */ public class BusinessTargetServiceImpl
/*     */   implements BusinessTargetService
/*     */ {
/*     */   private ManageSetDAO manageSetDAO;
/*     */   private DepartmentDAO departmentDAO;
/*     */   private BusinessTargetDAO businessTargetDAO;
/*     */   private UserDAO userDAO;
/*     */ 
/*     */   public ManageSetDAO getManageSetDAO()
/*     */   {
/*  36 */     return this.manageSetDAO;
/*     */   }
/*     */ 
/*     */   public void setManageSetDAO(ManageSetDAO manageSetDAO) {
/*  40 */     this.manageSetDAO = manageSetDAO;
/*     */   }
/*     */ 
/*     */   public DepartmentDAO getDepartmentDAO() {
/*  44 */     return this.departmentDAO;
/*     */   }
/*     */ 
/*     */   public void setDepartmentDAO(DepartmentDAO departmentDAO) {
/*  48 */     this.departmentDAO = departmentDAO;
/*     */   }
/*     */ 
/*     */   public BusinessTargetDAO getBusinessTargetDAO() {
/*  52 */     return this.businessTargetDAO;
/*     */   }
/*     */ 
/*     */   public void setBusinessTargetDAO(BusinessTargetDAO businessTargetDAO) {
/*  56 */     this.businessTargetDAO = businessTargetDAO;
/*     */   }
/*     */ 
/*     */   public UserDAO getUserDAO() {
/*  60 */     return this.userDAO;
/*     */   }
/*     */ 
/*     */   public void setUserDAO(UserDAO userDAO) {
/*  64 */     this.userDAO = userDAO;
/*     */   }
/*     */ 
/*     */   public BusinessTargetForm getBusinessTargetSettings(String deptIds) {
/*  68 */     BusinessTargetForm businessForm = new BusinessTargetForm();
/*     */ 
/*  70 */     ManageSet manageSet = new ManageSet();
/*  71 */     manageSet.setMType("11");
/*  72 */     manageSet.setStatus("1");
/*  73 */     manageSet = this.manageSetDAO.getManageSetByTypeStatus(manageSet);
/*  74 */     if (manageSet != null) {
/*  75 */       if ("isGrossProfit".equals(manageSet.getCode())) {
/*  76 */         businessForm.setAssessmentTypeName(manageSet.getNameKey());
/*  77 */         businessForm.setAssessmentTypeValue(manageSet.getMValue());
/*  78 */         businessForm.setAssessmentTypeName2(manageSet.getNameKey2());
/*     */       } else {
/*  80 */         businessForm.setAssessmentTypeName(manageSet.getNameKey());
/*     */       }
/*     */     }
/*     */ 
/*  84 */     manageSet = new ManageSet();
/*  85 */     manageSet.setMType("2");
/*  86 */     manageSet = this.manageSetDAO.getManageSetByTypeStatus(manageSet);
/*  87 */     if (manageSet != null) {
/*  88 */       businessForm.setTotalTarget(manageSet.getMValue());
/*  89 */       businessForm.setAssignPeriod(manageSet.getStatus());
/*     */ 
/*  91 */       if (!StringUtils.isEmpty(deptIds)) {
/*  92 */         String[] splitDeptIds = deptIds.split(",");
/*  93 */         if ((splitDeptIds != null) && (splitDeptIds.length > 0))
/*  94 */           for (int j = 0; j < splitDeptIds.length; j++)
/*  95 */             if (splitDeptIds[j] != "") {
/*  96 */               Department department = new Department();
/*  97 */               department = this.departmentDAO.getDepartment(Integer.valueOf(Integer.parseInt(splitDeptIds[j])));
/*     */ 
/*  99 */               businessForm.getAssignDepts().add(department);
/*     */             }
/*     */       }
/*     */       else
/*     */       {
/* 104 */         List manageObjects = new ArrayList();
/* 105 */         manageObjects = this.manageSetDAO.getManageSetObjectByManageSetId(manageSet.getId());
/* 106 */         if ((manageObjects != null) && (manageObjects.size() > 0)) {
/* 107 */           for (int i = 0; i < manageObjects.size(); i++) {
/* 108 */             ManageSetObject manageObject = new ManageSetObject();
/* 109 */             manageObject = (ManageSetObject)manageObjects.get(i);
/*     */ 
/* 111 */             Department department = new Department();
/* 112 */             department = this.departmentDAO.getDepartment(manageObject.getOtherId());
/*     */ 
/* 114 */             businessForm.getAssignDepts().add(department);
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 119 */     return businessForm;
/*     */   }
/*     */ 
/*     */   public List getCurMonthTargetSalePerson(String deptIds) {
/* 123 */     if ((deptIds == null) || ("".equals(deptIds))) return null;
/* 124 */     String[] strDeptIds = deptIds.split(",");
/* 125 */     if ((strDeptIds == null) && (strDeptIds.length <= 0)) return null;
/*     */ 
/* 127 */     List monthTargets = new ArrayList();
/* 128 */     for (int i = 0; i < strDeptIds.length; i++) {
/* 129 */       Department dept = new Department();
/* 130 */       dept = this.departmentDAO.getDepartment(Integer.valueOf(Integer.parseInt(strDeptIds[i])));
/* 131 */       if (dept != null) {
/* 132 */         List users = new ArrayList();
/* 133 */         users = this.userDAO.getUserActivityByDeptId(dept.getId());
/* 134 */         if ((users != null) && (users.size() > 0)) {
/* 135 */           for (int j = 0; j < users.size(); j++) {
/* 136 */             Users user = new Users();
/* 137 */             user = (Users)users.get(j);
/* 138 */             user.setBusinessTarget(this.businessTargetDAO.getCurMonthTargetBySalePersonId(user.getId()));
/*     */           }
/* 140 */           dept.getUsers().addAll(users);
/* 141 */           monthTargets.add(dept);
/*     */         }
/*     */       }
/*     */     }
/* 145 */     return monthTargets;
/*     */   }
/*     */ 
/*     */   public List getCurSeasonTargetSalePerson(String deptIds) {
/* 149 */     if ((deptIds == null) || ("".equals(deptIds))) return null;
/* 150 */     String[] strDeptIds = deptIds.split(",");
/* 151 */     if ((strDeptIds == null) && (strDeptIds.length <= 0)) return null;
/*     */ 
/* 153 */     List seasonTargets = new ArrayList();
/* 154 */     for (int i = 0; i < strDeptIds.length; i++) {
/* 155 */       Department dept = new Department();
/* 156 */       dept = this.departmentDAO.getDepartment(Integer.valueOf(Integer.parseInt(strDeptIds[i])));
/* 157 */       if (dept != null) {
/* 158 */         List users = new ArrayList();
/* 159 */         users = this.userDAO.getUserActivityByDeptId(dept.getId());
/* 160 */         if ((users != null) && (users.size() > 0)) {
/* 161 */           for (int j = 0; j < users.size(); j++) {
/* 162 */             Users user = new Users();
/* 163 */             user = (Users)users.get(j);
/* 164 */             user.setBusinessTarget(this.businessTargetDAO.getCurSeasonTargetBySalePersonId(user.getId()));
/*     */           }
/* 166 */           dept.getUsers().addAll(users);
/* 167 */           seasonTargets.add(dept);
/*     */         }
/*     */       }
/*     */     }
/* 171 */     return seasonTargets;
/*     */   }
/*     */ 
/*     */   public List getCurYearTargetSalePerson(String deptIds) {
/* 175 */     if ((deptIds == null) || ("".equals(deptIds))) return null;
/* 176 */     String[] strDeptIds = deptIds.split(",");
/* 177 */     if ((strDeptIds == null) && (strDeptIds.length <= 0)) return null;
/*     */ 
/* 179 */     List yearTargets = new ArrayList();
/* 180 */     for (int i = 0; i < strDeptIds.length; i++) {
/* 181 */       Department dept = new Department();
/* 182 */       dept = this.departmentDAO.getDepartment(Integer.valueOf(Integer.parseInt(strDeptIds[i])));
/* 183 */       if (dept != null) {
/* 184 */         List users = new ArrayList();
/* 185 */         users = this.userDAO.getUserActivityByDeptId(dept.getId());
/* 186 */         if ((users != null) && (users.size() > 0)) {
/* 187 */           for (int j = 0; j < users.size(); j++) {
/* 188 */             Users user = new Users();
/* 189 */             user = (Users)users.get(j);
/* 190 */             user.setBusinessTarget(this.businessTargetDAO.getCurYearTargetBySalePersonId(user.getId()));
/*     */           }
/* 192 */           dept.getUsers().addAll(users);
/* 193 */           yearTargets.add(dept);
/*     */         }
/*     */       }
/*     */     }
/* 197 */     return yearTargets;
/*     */   }
/*     */ 
/*     */   public boolean updateBusinessTarget(String deptIds, String assignPeriod, MonthTargetForm monthTargetForm)
/*     */   {
/* 202 */     boolean result1 = false;
/* 203 */     boolean result2 = false;
/* 204 */     ManageSet manageSet = new ManageSet();
/* 205 */     manageSet.setCode("isBusinessTarget");
/* 206 */     manageSet.setStatus(assignPeriod);
/* 207 */     manageSet.setMValue(monthTargetForm.getTotalTarget().toString());
/* 208 */     result1 = this.manageSetDAO.updateManageSetByCode(manageSet);
/*     */ 
/* 210 */     manageSet = new ManageSet();
/* 211 */     manageSet.setMType("2");
/* 212 */     manageSet = this.manageSetDAO.getManageSetByTypeStatus(manageSet);
/* 213 */     if (manageSet == null) return false;
/* 214 */     this.manageSetDAO.deleteManageSetObject(manageSet.getId());
/* 215 */     if (StringUtils.isEmpty(deptIds)) return false;
/* 216 */     String[] strDeptIds = deptIds.split(",");
/* 217 */     if ((strDeptIds != null) && (strDeptIds.length > 0)) {
/* 218 */       for (int i = 0; i < strDeptIds.length; i++) {
/* 219 */         if (strDeptIds[i] != "") {
/* 220 */           ManageSetObject manageSetObject = new ManageSetObject();
/* 221 */           manageSetObject.setManageSetId(manageSet.getId());
/* 222 */           manageSetObject.setOtherId(Integer.valueOf(Integer.parseInt(strDeptIds[i])));
/* 223 */           this.manageSetDAO.insertManageSetObject(manageSetObject);
/*     */         }
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 229 */     if ("1".equals(assignPeriod))
/* 230 */       updateMonthTarget(monthTargetForm);
/* 231 */     else if ("2".equals(assignPeriod))
/*     */     {
/* 233 */       updateSeasonTarget(monthTargetForm);
/* 234 */     } else if ("3".equals(assignPeriod)) {
/* 235 */       updateYearTarget(monthTargetForm);
/*     */     }
/*     */ 
/* 238 */     return result1;
/*     */   }
/*     */ 
/*     */   private void updateMonthTarget(MonthTargetForm monthTargetForm)
/*     */   {
/* 243 */     this.businessTargetDAO.deleteBusinessTargetByYear(DateUtils.getDateByFormat("yyyy"));
/* 244 */     Integer[] userIds = monthTargetForm.getUserId();
/* 245 */     BigDecimal[] januaryTargets = monthTargetForm.getJanuaryTarget();
/* 246 */     BigDecimal[] februaryTargets = monthTargetForm.getFebruaryTarget();
/* 247 */     BigDecimal[] marchTargets = monthTargetForm.getMarchTarget();
/* 248 */     BigDecimal[] aprilTargets = monthTargetForm.getAprilTarget();
/* 249 */     BigDecimal[] mayTargets = monthTargetForm.getMayTarget();
/* 250 */     BigDecimal[] juneTargets = monthTargetForm.getJuneTarget();
/* 251 */     BigDecimal[] julyTargets = monthTargetForm.getJulyTarget();
/* 252 */     BigDecimal[] augustTargets = monthTargetForm.getAugustTarget();
/* 253 */     BigDecimal[] septemberTargets = monthTargetForm.getSeptemberTarget();
/* 254 */     BigDecimal[] octoberTargets = monthTargetForm.getOctoberTarget();
/* 255 */     BigDecimal[] novemberTargets = monthTargetForm.getNovemberTarget();
/* 256 */     BigDecimal[] decemberTargets = monthTargetForm.getDecemberTarget();
/* 257 */     if ((userIds == null) || (userIds.length <= 0)) return;
/* 258 */     if ((userIds != null) && (januaryTargets != null) && (februaryTargets != null) && 
/* 259 */       (marchTargets != null) && (aprilTargets != null) && (mayTargets != null) && 
/* 260 */       (juneTargets != null) && (julyTargets != null) && (augustTargets != null) && 
/* 261 */       (septemberTargets != null) && (octoberTargets != null) && (novemberTargets != null) && 
/* 262 */       (decemberTargets != null))
/* 263 */       for (int i = 0; i < userIds.length; i++) {
/* 264 */         BusinessTarget businessTarget = new BusinessTarget();
/* 265 */         businessTarget.setSalePersonId(userIds[i]);
/* 266 */         businessTarget.setYear(DateUtils.getDateByFormat("yyyy"));
/* 267 */         businessTarget.setJanuaryTarget(januaryTargets[i]);
/* 268 */         businessTarget.setFebruaryTarget(februaryTargets[i]);
/* 269 */         businessTarget.setMarchTarget(marchTargets[i]);
/* 270 */         businessTarget.setAprilTarget(aprilTargets[i]);
/* 271 */         businessTarget.setMayTarget(mayTargets[i]);
/* 272 */         businessTarget.setJuneTarget(juneTargets[i]);
/* 273 */         businessTarget.setJulyTarget(julyTargets[i]);
/* 274 */         businessTarget.setAugustTarget(augustTargets[i]);
/* 275 */         businessTarget.setSeptemberTarget(septemberTargets[i]);
/* 276 */         businessTarget.setOctoberTarget(octoberTargets[i]);
/* 277 */         businessTarget.setNovemberTarget(novemberTargets[i]);
/* 278 */         businessTarget.setDecemberTarget(decemberTargets[i]);
/* 279 */         this.businessTargetDAO.insertBusinessTarget(businessTarget);
/*     */       }
/*     */   }
/*     */ 
/*     */   private void updateSeasonTarget(MonthTargetForm monthTargetForm)
/*     */   {
/* 286 */     this.businessTargetDAO.deleteBusinessTargetByYear(DateUtils.getDateByFormat("yyyy"));
/* 287 */     Integer[] userIds = monthTargetForm.getUserId();
/* 288 */     BigDecimal[] januaryTargets = monthTargetForm.getJanuaryTarget();
/* 289 */     BigDecimal[] aprilTargets = monthTargetForm.getAprilTarget();
/* 290 */     BigDecimal[] julyTargets = monthTargetForm.getJulyTarget();
/* 291 */     BigDecimal[] octoberTargets = monthTargetForm.getOctoberTarget();
/* 292 */     if ((userIds == null) || (userIds.length <= 0)) return;
/* 293 */     if ((userIds != null) && (januaryTargets != null) && (aprilTargets != null) && 
/* 294 */       (julyTargets != null) && (octoberTargets != null)) { System.out.println("process...... ");
/* 295 */       for (int i = 0; i < userIds.length; i++) {
/* 296 */         BusinessTarget businessTarget = new BusinessTarget();
/* 297 */         businessTarget.setSalePersonId(userIds[i]);
/* 298 */         businessTarget.setYear(DateUtils.getDateByFormat("yyyy"));
/* 299 */         BigDecimal monthTarget = new BigDecimal(0);
/* 300 */         if (januaryTargets[i].compareTo(new BigDecimal(0)) > 0) {
/* 301 */           monthTarget = januaryTargets[i].divide(new BigDecimal(3), 12, 4);
/* 302 */           businessTarget.setJanuaryTarget(monthTarget);
/* 303 */           businessTarget.setFebruaryTarget(monthTarget);
/* 304 */           businessTarget.setMarchTarget(monthTarget);
/*     */         } else {
/* 306 */           businessTarget.setJanuaryTarget(new BigDecimal(0));
/* 307 */           businessTarget.setFebruaryTarget(new BigDecimal(0));
/* 308 */           businessTarget.setMarchTarget(new BigDecimal(0));
/*     */         }
/*     */ 
/* 311 */         if (aprilTargets[i].compareTo(new BigDecimal(0)) > 0) {
/* 312 */           monthTarget = new BigDecimal(0);
/* 313 */           monthTarget = aprilTargets[i].divide(new BigDecimal(3), 12, 4);
/* 314 */           businessTarget.setAprilTarget(monthTarget);
/* 315 */           businessTarget.setMayTarget(monthTarget);
/* 316 */           businessTarget.setJuneTarget(monthTarget);
/*     */         } else {
/* 318 */           businessTarget.setAprilTarget(new BigDecimal(0));
/* 319 */           businessTarget.setMayTarget(new BigDecimal(0));
/* 320 */           businessTarget.setJuneTarget(new BigDecimal(0));
/*     */         }
/*     */ 
/* 323 */         if (julyTargets[i].compareTo(new BigDecimal(0)) > 0) {
/* 324 */           monthTarget = new BigDecimal(0);
/* 325 */           monthTarget = julyTargets[i].divide(new BigDecimal(3), 12, 4);
/* 326 */           businessTarget.setJulyTarget(monthTarget);
/* 327 */           businessTarget.setAugustTarget(monthTarget);
/* 328 */           businessTarget.setSeptemberTarget(monthTarget);
/*     */         } else {
/* 330 */           businessTarget.setJulyTarget(new BigDecimal(0));
/* 331 */           businessTarget.setAugustTarget(new BigDecimal(0));
/* 332 */           businessTarget.setSeptemberTarget(new BigDecimal(0));
/*     */         }
/*     */ 
/* 335 */         if (octoberTargets[i].compareTo(new BigDecimal(0)) > 0) {
/* 336 */           monthTarget = new BigDecimal(0);
/* 337 */           monthTarget = octoberTargets[i].divide(new BigDecimal(3), 12, 4);
/* 338 */           businessTarget.setOctoberTarget(monthTarget);
/* 339 */           businessTarget.setNovemberTarget(monthTarget);
/* 340 */           businessTarget.setDecemberTarget(monthTarget);
/*     */         } else {
/* 342 */           businessTarget.setOctoberTarget(new BigDecimal(0));
/* 343 */           businessTarget.setNovemberTarget(new BigDecimal(0));
/* 344 */           businessTarget.setDecemberTarget(new BigDecimal(0));
/*     */         }
/*     */ 
/* 347 */         this.businessTargetDAO.insertBusinessTarget(businessTarget);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   private void updateYearTarget(MonthTargetForm monthTargetForm)
/*     */   {
/* 354 */     this.businessTargetDAO.deleteBusinessTargetByYear(DateUtils.getDateByFormat("yyyy"));
/* 355 */     Integer[] userIds = monthTargetForm.getUserId();
/* 356 */     BigDecimal[] januaryTargets = monthTargetForm.getJanuaryTarget();
/* 357 */     if ((userIds == null) || (userIds.length <= 0)) return;
/* 358 */     if ((userIds != null) && (januaryTargets != null))
/* 359 */       for (int i = 0; i < userIds.length; i++) {
/* 360 */         BusinessTarget businessTarget = new BusinessTarget();
/* 361 */         businessTarget.setSalePersonId(userIds[i]);
/* 362 */         businessTarget.setYear(DateUtils.getDateByFormat("yyyy"));
/* 363 */         BigDecimal monthTarget = new BigDecimal(0);
/* 364 */         if (januaryTargets[i].compareTo(new BigDecimal(0)) > 0) {
/* 365 */           monthTarget = januaryTargets[i].divide(new BigDecimal(12), 12, 4);
/*     */         }
/* 367 */         businessTarget.setJanuaryTarget(monthTarget);
/* 368 */         businessTarget.setFebruaryTarget(monthTarget);
/* 369 */         businessTarget.setMarchTarget(monthTarget);
/* 370 */         businessTarget.setAprilTarget(monthTarget);
/* 371 */         businessTarget.setMayTarget(monthTarget);
/* 372 */         businessTarget.setJuneTarget(monthTarget);
/* 373 */         businessTarget.setJulyTarget(monthTarget);
/* 374 */         businessTarget.setAugustTarget(monthTarget);
/* 375 */         businessTarget.setSeptemberTarget(monthTarget);
/* 376 */         businessTarget.setOctoberTarget(monthTarget);
/* 377 */         businessTarget.setNovemberTarget(monthTarget);
/* 378 */         businessTarget.setDecemberTarget(monthTarget);
/* 379 */         this.businessTargetDAO.insertBusinessTarget(businessTarget);
/*     */       }
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.service.impl.BusinessTargetServiceImpl
 * JD-Core Version:    0.6.0
 */